﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Polaris.Domain.Interfaces.Admin;
using Polaris.Domain.Model.Dto.Sys_Menu.Request;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;

namespace Polaris.WebApi.Controllers.Admin
{
    /// <summary>
    /// 菜单接口
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Sys_MenuController : BaseController
    {
        private readonly ISys_Menu _sys_Menu;

        public Sys_MenuController(ISys_Menu sys_Menu)
        {
            _sys_Menu = sys_Menu;
        }

        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMenuList([FromQuery] SearchMenuRequest search)
        {
            return SUCCESS(await _sys_Menu.GetMenuList(search));
        }

        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="create"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> CreateMenu(CreateMenuRequest create)
        {
            await _sys_Menu.CreateMenu(create, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="update"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdateMenu(UpdateMenuRequest update)
        {
            await _sys_Menu.UpdateMenu(update, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DeleteMenu(string id)
        {
            await _sys_Menu.DeleteMenu(id, null);
            return SUCCESS("OK");
        }

        /// <summary>
        /// 根据id获取菜单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMenuById(string id)
        {
            var result = await _sys_Menu.GetMenuById(Guid.Parse(id));
            return SUCCESS(result);
        }

        /// <summary>
        /// 获取树形菜单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> GetMenuTree()
        {
            var reuslt = await _sys_Menu.GetMenuTree();
            return SUCCESS(reuslt);
        }

    }
}
